﻿
 
g_bool_edit = false;				//是否修改状态
g_bool_edit_query = false;			//修改状态, 是否查询了数据

//-------------页面初始化-----------------------------------------------------
function initPage()
{
    GetListType_1();  //查找一级类
}

//-------------查找分类-----------------------------------------------------
function GetListType_1()
{  
	//初始化面板
	var tmpArray = new Array("cost", "trousers", "skirt", "coat");
	for(var index in tmpArray)
	{
		var name = tmpArray[index];
		DisabledObj(name +"_tab", true);
		DisplayObj(name +"_table", "none");
	}
	//获取类别信息
	on_select_change_type2();
}
function on_select_change_type2()
{  
	tmpTypeVal_1 = "clothing";      	//当前选择类别1
	tmpTypeVal = "dress";      		    //当前选择类别2
	var data = "&typeName_1=" + tmpTypeVal_1;
	data += "&typeName=" + tmpTypeVal;
	PostToPHP(__on_select_change_type2_callback, "info", "query_type_3", data); 
}
function __on_select_change_type2_callback(text)
{
	//alert(text);
	var jsonObj = String2JSON(text);
	var ds = GetDataSet(jsonObj);
	if(ds && ds[0])
	{
        FillSelectObj("type_3", ds[0]);
		JudgeURL();  ////判断url   
        OnGetData();  //获取某条记录
	}
}

var g_str_goods_id = "0"; 

//--------判断url 是否存在id, 存在则查询记录， 不存在则表示是新增加---------------------------------------
function JudgeURL()
{
    g_str_goods_id = GetUrlParm("id"); 
    if(!g_bool_edit && g_str_goods_id && g_str_goods_id.length > 0)
    {   
		g_bool_edit = true;  //修改状态 
    } 
}

//------获取某条记录---------------------------------------------------------------
function OnGetData()
{  
	if(g_bool_edit && !g_bool_edit_query)  //修改状态, 未获取记录, 则获取记录
	{
		var data = "&id=" + g_str_goods_id;
		PostToPHP(__OnGetDataCallback, "info", "select_goods_dress_info", data);
	}
}
function __OnGetDataCallback(text)
{
	g_bool_edit_query = true; //修改状态, 查询了数据
	
    //alert(text);   
    var jsonObj = String2JSON(text);
	var ds = GetDataSet(jsonObj);
	
	 for(var type_2 in ds)
	 {		
		if(ds[type_2])
		{   
			var items = ds[type_2][0]; 
			
			var tmpPrefix = "";
			if(type_2 != "dress")
			{
				tmpPrefix = type_2 + "_";
				clickCheckUploadType(type_2);  //点击上传类型控件
			}
			
			for(var name in items)		//根据字段名给控件赋值
			{ 
				tmpObj = $(tmpPrefix + name);   
				if(tmpObj)
				{	
					tmpObj.value = items[name];
				}
			}
			
			if(type_2 == "dress")  //套装主表无文件
				continue;
	 
			bFile_0 = (items["file_0"] == "true"); //文件是否存在
			bFile_1 = (items["file_1"] == "true");
			bFile_2 = (items["file_2"] == "true");
			bFile_3 = (items["file_3"] == "true");
			bFile_4 = (items["file_4"] == "true");
	 
			strPossfix = GetFilePostfix(); 		//文件后缀 
			 
			var tempStr = items["filepath"] + items["goods_id"] + "_" + items["sex"] + "_";     
			if(bFile_0)  
				InitFileSapn(tmpPrefix +"span_file_0", tmpPrefix +"file_0", tempStr+"0."+strPossfix); 
			if(bFile_1)
				InitFileSapn(tmpPrefix +"span_file_1", tmpPrefix +"file_1", tempStr+"1."+strPossfix);
			if(bFile_2)
				InitFileSapn(tmpPrefix +"span_file_2", tmpPrefix +"file_2", tempStr+"2."+strPossfix); 
			if(bFile_3) 
				InitFileSapn(tmpPrefix +"span_file_3", tmpPrefix +"file_3", tempStr+"3."+strPossfix); 
			if(bFile_4) 
				InitFileSapn(tmpPrefix +"span_file_4", tmpPrefix +"file_4", tempStr+"4."+strPossfix); 
		 } 
	}
}
//初始化span
function InitFileSapn(spanID, fileInputID, filePath)
{ 
    DisabledObj(fileInputID, true);  //禁用file控件
    DisplayObj(fileInputID, "none"); //隐藏file控件    
    
    AppendElementText(spanID, "    ");
    AppendElementA(spanID, "OnChangeFile", fileInputID, "修改"); 
    AppendElementText(spanID, "    ");
    
    AppendElementA(spanID, "OnCancel", fileInputID, "取消");
    AppendElementText(spanID, "    ");
    
    var swfPath = GetSwfFileRootPath() + filePath;
    AppendElementA2(spanID, swfPath);
} 
//修改
function OnChangeFile(fileInputID)
{  
    DisplayObj(fileInputID, "");
    DisabledObj(fileInputID, false);
}
//取消
function OnCancel(fileInputID)
{  
    DisabledObj(fileInputID, true);
    DisplayObj(fileInputID, "none");
} 

//------------------------------------------------
//--选择某种上传类型
function clickCheckUploadType(typeName)
{
	tmpCheckObjName = typeName + "_check";
	tmpCheckObj = $(tmpCheckObjName);
	if(!tmpCheckObj)
		return;
	tmpCheckObj.checked = true;
	onClickCheckUploadType(typeName);
}
//选择上传的类型
function onClickCheckUploadType(typeName)
{	
	tmpCheckObjName = typeName + "_check";
	tmpCheckObj = $(tmpCheckObjName);
	if(!tmpCheckObj)
		return;
	
	tmpDisableType = !tmpCheckObj.checked;
	DisabledObj(typeName + "_tab", tmpDisableType);

	if(tmpCheckObj.checked) selectTabType(typeName);
	else DisplayObj(typeName+"_table", "none");
} 
//点击选项卡
function selectTabType(typeName)
{
	tmpCheckObjName = typeName + "_tab";
	tmpCheckObj = $(tmpCheckObjName);
	if(tmpCheckObj)
	{
		tmpCheckObj.checked = true;
		
		var tmpArray = new Array("cost", "trousers", "skirt", "coat");
		for(var index in tmpArray)
		{
			var name = tmpArray[index]; 
			DisplayObj(name +"_table", "none");
		} 
		DisplayObj(typeName+"_table", "");
	}
}

//----修改或插入提交之前判断-------------------------------------------
function submit_before()
{
	$('form').action = GetSwfFileRootPath() + "main.php"; 
	//$('command_type').value = $('type_1').value;
	
    //if($("file_2")) return CheckFilePostfix_ext("file_0", "file_1", "file_2"); 
    //else return CheckFilePostfix_ext("file_0", "file_1");
}